library shop;

import 'dart:async';
import 'dart:convert';
import 'package:shop/tools/image_upload.dart';

import 'app_config.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:image_picker/image_picker.dart';
import 'package:shared_preferences/shared_preferences.dart';
// import 'package:provider/provider.dart';
import 'package:shop/pages/goods/overview_page.dart';
import 'package:shop/tools/jump.dart';
import 'modules/production_modules.dart';
import 'tools/dio/interpretors.dart';
import 'popup/apptools.dart';
import 'popup/popups.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:dio/dio.dart';

part 'modules/user_modules.dart';

part 'pages/goods/new_post_page.dart';

part 'pages/goods/buy_page.dart';

part 'pages/user/user_page.dart';

part 'pages/user/register_page.dart';

part 'pages/production_page.dart';

part 'pages/user/login_page.dart';

part 'encapsulation/user_encapsulation.dart';

part 'pages/goods/detail_page.dart';

part 'encapsulation/goods_encapsulation.dart';

part 'pages/liked_page.dart';

part 'pages/goods/post_page.dart';

part 'pages/PermissionUtils.dart';

part 'pages/imagePicker_page.dart';

part 'pages/choosePicture_page.dart';



void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  State<StatefulWidget> createState() => MyAppState();
}

class MyAppState extends State<MyApp> {
  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      // routes: {
      //   // "/OverviewGoods": (context) => OverviewGoodsPage(),
      //   "/DetailGoods": (context) => DetailGoodsPage(),
      //   "/LikedGoods": (context) => LikedPage(),
      //   // "/User": (context) => const UserPage(), //配置路由
      // },
      title: '二手市场',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const HomePage(),
    );
  }
}

class HomePage extends StatefulWidget {
  const HomePage({Key? key}) : super(key: key);
  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  int _selected = 0;

  @override
  Widget build(BuildContext context) {
    func(int index){setState(() {
      _selected=index;
    });}
    return Scaffold(
      extendBody: true,
      extendBodyBehindAppBar: true,
      body: IndexedStack(
        sizing: StackFit.expand,
        alignment: Alignment.topCenter,
        index: _selected,
        children: [
          OverviewGoodsPage(tracker: func,),
          const NewPostPage(),
          const UserPage(),
          // DetailPage()
        ],
      ),
      bottomNavigationBar: BottomNavigationBar(
        currentIndex: _selected,
        items: const [
          BottomNavigationBarItem(icon: Icon(Icons.home), label: "home"),
          BottomNavigationBarItem(icon: Icon(Icons.add_circle_outline,size: 30,),label: "publish"),
          BottomNavigationBarItem(icon: Icon(Icons.account_circle), label: "user"),
          // BottomNavigationBarItem(icon: Icon(Icons.code), label: "test"),
        ],
        onTap: (int index) {
          setState(() {
            _selected = index;
          });
        },
      ),
    );
  }
}
